#include<bits/stdc++.h>
using namespace std;
int t,n,a[200010],redlast,bluelast;
unsigned long long ans;
unsigned long long Max(unsigned long long xx,unsigned long long yy) {
    return xx > yy? xx: yy;
}
void dfs(int dep,int redlast,int bluelast,unsigned long long score) {
    if (dep > n) {
        ans = Max(ans,score);
        return;
    }
    if (a[redlast] == a[dep]) dfs(dep + 1,dep,bluelast,score + a[dep]);
    else dfs(dep + 1,dep,bluelast,score);
    if (a[bluelast] == a[dep]) dfs(dep + 1,redlast,dep,score + a[dep]);
    else dfs(dep + 1,redlast,dep,score);
    return;
}
int main() {
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    scanf("%d",&t);
    for (int i = 1;i <= t;i ++) {
        ans = 0;
        scanf("%d",&n);
        for  (int i = 1;i <= n;i ++)
            scanf("%d",&a[i]);//a[i]>=1
        dfs(1,0,0,0);
        printf("%llu\n",ans);
    }
    return 0;
}
